package com.jwdf.uda.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.jwdf.uda.R;

public class ProgressDialog extends FrameLayout {
    //    private TextView mTvMsg;
    private AnimationDrawable mAnimDrawable;

    private void initViews(Context context) {
        View contentView = LayoutInflater.from(context).inflate(R.layout.view_progress, null);
        this.addView(contentView);
//        mTvMsg = (TextView) findViewById(R.id.tvMsg);
        mAnimDrawable = (AnimationDrawable) contentView.findViewById(R.id.iv_load).getBackground();
    }

    public ProgressDialog(Context context) {
        super(context);
        initViews(context);
    }

    public ProgressDialog(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }

//    private void setTipMsg(String msg) {
//        mTvMsg.setText(TextUtils.isEmpty(msg) ? "加载中..." : msg);
//    }

    public void show() {
//        setTipMsg("");
        this.setVisibility(View.VISIBLE);
        mAnimDrawable.start();
    }

    public void show(int resId) {
        show(getResources().getString(resId));
    }

    public void show(String msg) {
//        setTipMsg(msg);
        this.setVisibility(View.VISIBLE);
    }

    public void close() {
        if (isShowing() && mAnimDrawable.isRunning()) {
            this.setVisibility(View.GONE);
            mAnimDrawable.stop();
        }
    }

    public boolean isShowing() {
        return View.VISIBLE == this.getVisibility();
    }
}
